package avicit.bdp.dds.dao.mapper;


import avicit.bdp.dds.dispatch.enums.AlertStatus;
import avicit.bdp.dds.dao.entity.Alert;
import avicit.platform6.commons.utils.ComUtil;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.Map;

/**
 * @金航数码科技有限责任公司
 * @作者：developer
 * @邮箱：developer@avic-digital.com
 * @创建时间： 2020-06-24 14:54
 * @类说明：ProcessDefinitionRest
 * @修改记录：
 */
@RunWith(SpringRunner.class)
@SpringBootTest
@Transactional
@Rollback(true)
public class AlertMapperTest {

    @Autowired
    private AlertMapper alertMapper;

    /**
     * test insert
     * @return
     */
    @Test(timeout = 60*1000)
    public void testInsert(){
//        Alert expectedAlert = createAlert();
//        assertNotNull(expectedAlert.getId());
//        assertThat(expectedAlert.getId(), greaterThan(0));
    }

    /**
     *  create alert map
     * @param count alert count
     * @param alertStatus alert status
     * @return alert map
     */
    private Map<Integer,Alert> createAlertMap(Integer count, AlertStatus alertStatus){
        Map<Integer,Alert> alertMap = new HashMap<>();

        for (int i = 0 ; i < count ;i++){
            Alert alert = createAlert(alertStatus);
//            alertMap.put(alert.getId(),alert);
        }

        return alertMap;

    }


    /**
     * create alert
     * @return alert
     * @throws Exception
     */
    private Alert createAlert(){
        return createAlert(AlertStatus.WAIT_EXECUTION);
    }

    /**
     * create alert
     * @param alertStatus alert status
     * @return alert
     */
    private Alert createAlert(AlertStatus alertStatus){
        Alert alert = new Alert();
        alert.setId(ComUtil.getId());
//        alert.setShowType(ShowType.TABLE);
        alert.setTitle("test alert");
        alert.setContent("[{'type':'WORKER','host':'192.168.xx.xx','event':'server down','warning level':'serious'}]");
//        alert.setAlertType(AlertType.EMAIL);
        alert.setAlertStatus(alertStatus.getCode());
        alert.setLog("success");
//        alert.setReceivers("aa@aa.com");
//        alert.setReceiversCc("bb@aa.com");
//        alert.setCreateTime(DateUtils.getCurrentDate());
//        alert.setUpdateTime(DateUtils.getCurrentDate());

        alertMapper.insert(alert);
        return alert;
    }
}
